package com.common.baselib.mvp;

import android.app.Activity;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public abstract class MvpBaseActivity<P extends MvpBasePresenter> extends AppCompatActivity implements IMvpBaseView {
    protected P presenter;
    private Activity context;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = this;
        presenter = createPresenter();
        if (presenter != null) {
            presenter.attachView(this);
        }
    }


    /*  protected <T extends View> T getView(@IdRes int resId) {
          return findViewById(resId);
      }*/
    public Activity getContext() {
        return context;
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (presenter != null) {
            presenter.detachView(false);
            presenter.onDestroy();
        }
    }

    protected abstract P createPresenter();

}
